<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<html>
<head>
    <meta charset="utf-8">
    <title>牛皮</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">

    <!-- 引入框架的js、css等 -->
    <jsp:include page="${request.contextPath}/static/include.jsp" flush="true" />

    <script type="text/html" id="tableBar">
        <a class="layui-btn layui-btn-xs" lay-event="add">添加子部门</a>
        <a class="layui-btn layui-btn-xs" lay-event="edit">修改</a>
        <a class="layui-btn layui-btn-xs layui-btn-danger" lay-event="del">删除</a>
        <a class="layui-btn layui-btn-xs layui-btn-danger" lay-event="up">上移</a>
        <a class="layui-btn layui-btn-xs layui-btn-danger" lay-event="down">下移</a>
    </script>
    <script type="text/javascript">
        var treeGrid;
        layui.config({
            base: '${request.contextPath}/libs/layuiExt/js/' //此处路径请自行处理, 可以使用绝对路径
        }).extend({
            treeGrid:'treeGrid'
        }).use([ 'form', 'layer', 'table', 'laydate', 'treeGrid'], function(){
            treeGrid = layui.treeGrid;
            var layer = parent.layer === undefined ? layui.layer : top.layer
                ,$ = layui.jquery
                ,laydate = layui.laydate
                ,table = layui.table
                ,layer = layui.layer;

            treeGrid.render({
                id: '_table'
                ,elem : '#_table'
                ,url : __ctxPath + '/framework/SysDept.do?method=list'
                ,toolbar: '#_leftTableToolbar'		//开启工具栏（动态列素筛选、导出、打印）
                ,cellMinWidth: 100
                ,idField:'lid'//必須字段
                ,treeId:'lid'//树形id字段名称
                ,treeUpId:'plid'//树形父id字段名称
                ,treeShowName:'cname'//以树形式显示的字段
                ,heightRemove:[".dHead",10]//不计算的高度,表格设定的是固定高度，此项不生效
                ,height:'full-60'
                ,isFilter:false//是否开启过滤
                ,iconOpen:false//是否显示图标【默认显示】
                ,loading:true
                ,method:'post'
                ,isPage:false
                ,cols: [[
                    {title: '操作', align:'center' ,templet : '#tableBar', width:300}
                    ,{field:'cname', title: '部门名称',sort:true}
                    ,{field:'description', title: '部门描述',sort:true}
                    ,{field:'operatorName', title: '操作人',sort:true}
                    ,{field:'operatorTime', title: '操作时间',sort:true}
                ]]
                ,onDblClickRow:function (index, o) {
                    //双击
                }
                ,done : function(res, curr, count){
                    $("#toAdd").click(function(){
                        toPage('system/sysDept/jsp/add.jsp', {width:'40%', height:'60%', title:'新增', plid:'-1', pdeptName:'无'})
                    });
                }
            });

            //监听table行内编辑按钮
            treeGrid.on('tool(_table)', function(obj) { //注：tool是工具条事件名，test是table原始容器的属性 lay-filter="对应的值"
                var layEvent = obj.event,
                    data = obj.data;

                if (layEvent === 'add') { //添加子部门
                    toPage('system/sysDept/jsp/add.jsp', {width:'40%', height:'60%', title:'新增', plid:data.lid, pdeptName:data.cname});
                }else if (layEvent === 'edit') { //修改
                    toPage("/framework/SysDept.do?method=toEditOrDetail", {lid: data.lid, pageType: TO_EDIT, pageUrl: "system/sysDept/jsp/update.jsp", width:'95%', height:'95%'});
                } else if (layEvent === 'del') { //删除
                    layer.confirm('确定删除该记录？', {icon : 3, title : '提示信息'}, function(index) {
                        $.post(__ctxPath+"/framework/SysDept.do?method=delete", {lid: data.lid}, function(response){
                            layer.close(index);
                            if(response.msg) layer.msg(response.msg);
                            if(response.code == RESPONSE_SUCCESS){
                                reloadTreeGrid(treeGrid);
                            }
                        });
                    });
                } else if(layEvent == 'up'){ //上移
                    /*if(1 == data.sort){
                        layer.msg("已经是最上了",{icon:2});
                        return;
                    }*/
                    ajax("/framework/SysDept.do?method=up", {lid:data.lid}, {}, treeGrid);
                    clearRepeatCommitCheck();
                } else if(layEvent == 'down'){ //下移
                    ajax("/framework/SysDept.do?method=down", {lid:data.lid}, {}, treeGrid);
                    clearRepeatCommitCheck();
                }
            });

            //查询刷新
            $(".search_btn").click(function(){
                treeGrid.reload('_table', {
                    where : serializeObject($("#_form"))
                });
            });

        });

    </script>
</head>
<body>
        <!-- 查询条件 -->
        <form class="layui-form" id="_form" action="">
            <div class="layui-inline">
                <label class="layui-form-label">部门名称</label>
                <div class="layui-input-inline">
                    <input type="text" name="where_cname_like" class="layui-input">
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label">部门负责人</label>
                <div class="layui-input-inline">
                    <input type="text" class="layui-input">
                </div>
            </div>
            <button type="button" class="layui-btn layui-icon search_btn custom" style="margin-left: 30px;padding: 0 10px;">&#xe615;&nbsp;查询</button>
            <button type="button" class="layui-btn layui-icon layui-btn-primary reset_btn custom" style="margin-left:5px;padding: 0 10px;">&#xe669;&nbsp;重置</button>
        </form>

        <div class="layui-row">
            <script type="text/html" id="_leftTableToolbar">
                <div class="table-tool-btn">
                    <button type="button" class="layui-btn layui-icon-add-1 layui-icon" id="toAdd">新增部门</button>
                </div>
            </script>
            <table id="_table" lay-filter="_table"></table>
        </div>
</body>
</html>
